<?php

namespace common\models\datas;

use common\components\behaviors\UpdateCacheBehavior;
use common\components\extenders\MenuManage;
use Yii;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%cate_attr}}".
 *
 * @property integer $id
 * @property integer $site_id
 * @property integer $cat_id
 * @property integer $pc_is_show
 * @property integer $mobile_is_show
 * @property integer $pc_sort
 * @property integer $mobile_sort
 * #116 分店分类管理 分类关联模型
 */
class CateAttr extends \common\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */

    public static function tableName()
    {
        return '{{%cate_attr}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['site_id', 'cat_id', 'pc_is_show', 'mobile_is_show', 'pc_sort', 'mobile_sort'], 'integer']
        ];
    }

    public function fields()
    {
        $fields = parent::fields();
        $fields['pc_is_show'] = function () {
            switch ($this->is_show) {
                case 0:
                    return \Yii::t('common', '不显示');
                case 1:
                    return \Yii::t('common', '显示');
            }
        };
        $fields['mobile_is_show'] = function () {
            switch ($this->is_show) {
                case 0:
                    return \Yii::t('common', '不显示');
                case 1:
                    return \Yii::t('common', '显示');
            }
        };
        $fields['is_delete'] = function () {
            switch ($this->is_show) {
                case 0:
                    return \Yii::t('common', '有效');
                case 1:
                    return \Yii::t('common', '删除');
            }
        };
        return $fields;
    }

    public function extraFields(){
        return [
            'frontend_operate' => function () {
                return (new MenuManage(MenuManage::RECORD_ITEM_TOOLBAR, $this->attributes))->create();
            },
        ];
    }
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', '自动编号'),
            'site_id' => Yii::t('common', '广场id'),
            'cat_id' => Yii::t('common', '分类id'),
            'pc_is_show' => Yii::t('common', 'pc端是否显示（1 显示 0 隐藏）'),
            'mobile_is_show' => Yii::t('common', '移动端是否显示（1显示 0 隐藏）'),
            'pc_sort' => Yii::t('common', 'pc端排序'),
            'mobile_sort' => Yii::t('common', '移动端排序'),
        ];
    }

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => UpdateCacheBehavior::className(),
                'cacheName' => 'CateGoodsCourse',
            ],

        ]);
    }
}
